package game.system;

import game.socket.GameThread;

public class UserVo implements UserImp{
	private static final String MSG_USER_OUT = "userOut?";
	private GameThread gameThread;//连接的线程资源
	
	private String id;
	private String name;
	private String ip;//当前ip
	
	public UserVo(){
	}
	
	/**
	 * 向用户发送信息
	 * @param msg
	 */
	public void send(String msg){
		this.gameThread.send(msg);
	}
	
	/**
	 * 打开一个用户，并且添加到用户列表
	 * @param gameThread
	 * @param pojo
	 */
	public void open(GameThread gameThread, String id, String name){
		this.gameThread = gameThread;
		this.ip = gameThread.getSocket().getLocalAddress().toString();
		this.id = id;
		this.name = name;
		UserModel.addUser(this);
	}
	
	/**
	 * 关闭用户回收信息
	 */
	public void close(){
		UserModel.removeUser(this.id);//在列表中删除
		this.gameThread = null;
	}
	
	public GameThread getGameThread() {
		return gameThread;
	}
	public void setGameThread(GameThread gameThread) {
		this.gameThread = gameThread;
		this.ip = gameThread.getSocket().getLocalAddress().toString();
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getIp() {
		return ip;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

}
